home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE03 / TYPECAST / SHAPESU.PAS < prev    next >
Pascal/Delphi Source File  |  1995-07-19  |  1KB  |  48 lines

  1. unit Shapesu;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     procedure FormKeyPress(Sender: TObject; var Key: Char);
  12.   private
  13.     { Private declarations }
  14.   public
  15.     { Public declarations }
  16.   end;
  17.  
  18. var
  19.   Form1: TForm1;
  20.  
  21. implementation
  22.  
  23. {$R *.DFM}
  24.  
  25. procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
  26. begin
  27.   { The variable with no name! }
  28.   with TShape.Create(Self) do
  29.   begin
  30.     Left := 0;
  31.     Top := 0;
  32.     { For Random to be truly random, we call }
  33.     { Randomize in the initialization section }
  34.     Width := Random(Self.ClientWidth);
  35.     Height := Random(Self.ClientHeight);
  36.     Brush.Color := RGB(Random(256), Random(256), Random(256));
  37.     Shape := TShapeType(Random(6));
  38.     Parent := Self;
  39.   end;
  40.   { We've done all that we want doing on this key press }
  41.   { Null the key to prevent any further key-press processing }
  42.   Key := #0;
  43. end;
  44.  
  45. initialization
  46.   Randomize;
  47. end.
  48.